package com.small.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.small.R;
import com.small.commom.Action;
import com.small.commom.AsyncImageLoader;
import com.small.commom.Common;
import com.small.model.FavShopModel;

public class FavShopAdapter extends BaseAdapter{

	List<FavShopModel> shopList;
	LayoutInflater li;
	public FavShopAdapter(Context co,List<FavShopModel> _list){
		this.li=LayoutInflater.from(co);
		shopList=_list;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return shopList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
//		// TODO Auto-generated method stub
//		convertView=null;
//		convertView=li.inflate(R.layout.mylook_list_item, null);
//		ImageView img=(ImageView)convertView.findViewById(R.id.itme_btn);
//		TextView txt_name=(TextView)convertView.findViewById(R.id.itme_txt);
//		
		FavShopModel  item= shopList.get(position);
		 
		ViewHolder holder=null; 
			
			if(null==convertView){
				holder =new ViewHolder(); 
//				convertView = View.inflate(mContext, R.layout.mylook_list_item, null); 
				convertView=li.inflate(R.layout.activity_favshop_list_item, null);
				holder.tv_title = (TextView) convertView.findViewById(R.id.tv_shop_name);     
		        holder.tv_content = (TextView) convertView.findViewById(R.id.tv_shop_secondname);
		        holder.tv_disctance = (TextView) convertView.findViewById(R.id.tv_disctance); 
		        holder.img_title = (ImageView) convertView.findViewById(R.id.img_shop);
		        convertView.setTag(holder);
			}else {
				holder = (ViewHolder) convertView.getTag();
			} 
			 
			holder.tv_title.setText(item.getParentShopName()+item.getShopName());
			holder.tv_content.setText(item.getShopName());
			holder.tv_disctance.setText("距离您"+Action.GetShortDistance(Common.lon, Common.lat, item.getShopLongitude(), item.getShopLatitude())+"米");
			String temp = "http://www.x99local.com:8089/upload_xjj/1/201212301201592434111.jpg";
			AsyncImageLoader.getInstance().loadPre(item.getShopID(),temp,holder.img_title);
			  
		
		return convertView; 		
	}
	private  class ViewHolder {    
    	public TextView tv_title;
    	public TextView tv_content;
    	public TextView tv_disctance;
    	public ImageView img_title;
    	 
	}
}
